#ifndef WIDGET_1_H
#define WIDGET_1_H

#include <QWidget>

#include <QUrl>
//http请求
#include <QUrlQuery>
#include <QNetworkReply>
#include <QJsonDocument>
#include <QJsonObject>

#include <QLabel>
#include <QListWidget>

#include <QFile>
#include <QFileDialog>
#include <QMediaPlaylist>
#include <QMediaPlayer>
#include <QMediaContent>
#include <QObject>

#include <QTimer>

#include <QSqlDatabase>  // 用于数据库连接
#include <QSqlQuery>     // 用于执行 SQL 查询
#include <QSqlError>     // 用于处理数据库操作错误
#include <QVariant>      // 用于处理查询结果
#include <QDebug>        // 用于调试信息输出

#include <QWidget>
#include <QResizeEvent>
#include <QLabel>

#include <QSet>

typedef struct Mediatype
{
    int ID;
    QString name;
    QUrl  Path;
}Mediatype;


namespace Ui {
class widget_1;
}

class widget_1 : public QWidget
{
    Q_OBJECT
private:
     QMediaPlayer *my_paly = new QMediaPlayer;

     QNetworkAccessManager *networkManager = new QNetworkAccessManager ; // 网络管理器

     QMediaPlaylist *music_list = new  QMediaPlaylist;

     QListWidget *listWidget;

     qint64 Media_TimeMax;

     bool ProgressBarDragState = false;
     bool PlayerStatus =false;

     QSet<QUrl> *FileNames_list = new QSet<QUrl>;
public:

    QLabel* background_main;
    QString formatTime(qint64 milliseconds);
public:
   QTimer *Media_time  = new QTimer(this);

    explicit widget_1(QWidget *parent = nullptr);
    ~widget_1();

protected:
   void resizeEvent(QResizeEvent *event);
private:
    // ===================== 数据库 成员 =====================
    QSqlDatabase db;  // 数据库连接
    QSqlQuery query;  // 查询对象

    Mediatype play_Media;  //正在播放的歌曲

    void sql_init(QString Path);
    bool add_Media_url(QUrl file_url);
    void up_data_list();
    Mediatype select_MediaUrlByname(QString MediaName);
    Mediatype select_MediaUrlID(int ID);



private slots:

    void on_horizontalSlider_actionTriggered(int action);
    void on_verticalSlider_actionTriggered(int action);
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    void requestMusicId(QString str);
private slots:

   void  onMusicCallback();    //获取音乐ID回调

   void on_pushButton_3_clicked();

   void on_pushButton_pre_clicked();

   void on_pushButton_next_clicked();

   void play_music(QListWidgetItem *item);
private:
    Ui::widget_1 *ui;
};

#endif // WIDGET_1_H
